home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / effects / dimmer2effect.win / bltmacros.h next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  38.9 KB  |  1,249 lines

  1. /*
  2.  
  3.     File:        BltMacros.h
  4.  
  5.     Contains:    Macros to help you handle multiple pixel formats
  6.                 in your effects components
  7.  
  8.     Written by:    Mike Dodd and Giovanni Agnoli
  9.  
  10.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  11.  
  12. */
  13.  
  14.  
  15. #ifndef __CONDITIONALMACROS__
  16. #include <ConditionalMacros.h>
  17. #endif
  18. #ifndef __MACTYPES__
  19. #include <MacTypes.h>
  20. #endif
  21.  
  22. #include <Endian.h>
  23.  
  24. #if PRAGMA_ONCE
  25. #pragma once
  26. #endif
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. #if PRAGMA_IMPORT
  33. #pragma import on
  34. #endif
  35.  
  36. #if PRAGMA_STRUCT_ALIGN
  37.     #pragma options align=mac68k
  38. #elif PRAGMA_STRUCT_PACKPUSH
  39.     #pragma pack(push, 2)
  40. #elif PRAGMA_STRUCT_PACK
  41.     #pragma pack(2)
  42. #endif
  43.  
  44.  
  45.  
  46. #if TARGET_RT_BIG_ENDIAN
  47.     #define B2NEndianRgnHandle(value)            
  48.     #define N2BEndianRgnHandle(value)            
  49.     #define B2NEndianPixMapHandle(value)        
  50.     #define N2BEndianPixMapHandle(value)        
  51. #endif
  52.  
  53.  
  54. //***** Here are the macros we know so well *****
  55.  
  56.  
  57. // These macros need renaming!  
  58. // Several issues: 
  59. //        swap-in-place vs. function return (eg. MyEndianRect currently is inconsistent with MyEndian16)
  60. //        4 different directions (BigToMine, MineToBig, LittleToMine, MineToLittle)
  61.  
  62. // General macros for swapping unconditionally
  63. #define Swapped16(a)        ((((a)&0xff)<<8) | ((unsigned short)(((a)&0xff00))>>8))
  64. #define SwappedS16(a)        ((short)Swapped16(a))
  65. #define SwappedU16(a)        ((unsigned short)Swapped16(a))
  66. #define Swapped32(a)        ((((a)&0xff)<<24) | (((a)&0xff00)<<8) | ((unsigned long)(((a)&0xff0000))>>8) | ((unsigned long)(((a)&0xff000000))>>24))
  67. #define SwappedS32(a)        ((long)Swapped32(a))
  68. #define SwappedU32(a)        ((unsigned long)Swapped32(a))
  69. #define SwapS16(a)            ((a)=SwappedS16(a))
  70. #define SwapU16(a)            ((a)=SwappedU16(a))
  71. #define SwapS32(a)            ((a)=SwappedS32(a))
  72. #define SwapU32(a)            ((a)=SwappedU32(a))
  73.  
  74.  
  75.  
  76. #define SwapS32Multiple(ptr,cnt) \
  77. {   long *__p = (long *)(ptr); \
  78.     long __i; \
  79.     for (__i=0;__i<(long)(cnt);__i++) {\
  80.         SwapS32(*__p); \
  81.         __p++; \
  82.     } \
  83. }
  84. #define SwapU32Multiple(ptr,cnt) \
  85. {   unsigned long *__p = (unsigned long *)(ptr); \
  86.     long __i; \
  87.     for (__i=0;__i<(long)(cnt);__i++) {\
  88.         SwapU32(*__p); \
  89.         __p++; \
  90.     } \
  91. }
  92. #define SwapS16Multiple(ptr,cnt) \
  93. {   short *__p = (short *)(ptr); \
  94.     long __i; \
  95.     for (__i=0;__i<(long)(cnt);__i++) { \
  96.         SwapS16(*__p); \
  97.         __p++; \
  98.     } \
  99. }
  100. #define SwapU16Multiple(ptr,cnt) \
  101. {   unsigned short *__p = (unsigned short *)(ptr); \
  102.     long __i; \
  103.     for (__i=0;__i<(long)(cnt);__i++) { \
  104.         SwapU16(*__p); \
  105.         __p++; \
  106.     } \
  107. }
  108.  
  109.  
  110.  
  111. #define SwapRect(a)    \
  112.         {    SwapU16((a).top); SwapU16((a).bottom); SwapU16((a).left); SwapU16((a).right); }
  113.             
  114.  
  115. #define SwapMatrix3by3(a)    \
  116.         {    SwapU32(a.matrix[0][0]); SwapU32(a.matrix[0][1]); SwapU32(a.matrix[0][2]);    \
  117.             SwapU32(a.matrix[1][0]); SwapU32(a.matrix[1][1]); SwapU32(a.matrix[1][2]);    \
  118.             SwapU32(a.matrix[2][0]); SwapU32(a.matrix[2][1]); SwapU32(a.matrix[2][2]);    }
  119.  
  120.  
  121.  
  122. #if TARGET_RT_LITTLE_ENDIAN
  123.  
  124. #define L2NEndianS16(a)                
  125. #define L2NEndianU16(a)                
  126.  
  127. #define L2NEndianS32(a)                
  128. #define L2NEndianU32(a)                
  129.  
  130. #define B2NEndianS16(a)                SwapS16(a)
  131. #define B2NEndianU16(a)                SwapU16(a)
  132.  
  133. #define B2NEndianS32(a)                SwapS32(a)
  134. #define B2NEndianU32(a)                SwapU32(a)
  135.  
  136. #define N2BEndianS32    B2NEndianS32
  137. #define N2BEndianU32    B2NEndianU32
  138.  
  139. #define N2LEndianS32    L2NEndianS32
  140. #define N2LEndianU32    L2NEndianU32
  141.  
  142. #define N2BEndianS16    B2NEndianS16
  143. #define N2BEndianU16    B2NEndianU16
  144.  
  145. #define N2LEndianS16    L2NEndianS16
  146. #define N2LEndianU16    L2NEndianU16
  147.  
  148. #define L2NEndianS16Multiple(a,b)
  149. #define L2NEndianU16Multiple(a,b)
  150.  
  151. #define L2NEndianS32Multiple(a,b)
  152. #define L2NEndianU32Multiple(a,b)
  153.  
  154. #define B2NEndianS16Multiple(a,b)    SwapS16Multiple(a,b)
  155. #define B2NEndianU16Multiple(a,b)    SwapU16Multiple(a,b)
  156.  
  157. #define B2NEndianS32Multiple(a,b)    SwapS32Multiple(a,b)    
  158. #define B2NEndianU32Multiple(a,b)    SwapU32Multiple(a,b)    
  159.  
  160. #define N2BEndianMatrix3by3(a)    SwapMatrix3by3(a)
  161. #define B2NEndianMatrix3by3(a)    SwapMatrix3by3(a)
  162. #define N2LEndianMatrix3by3(a)
  163. #define L2NEndianMatrix3by3(a)
  164.  
  165. #define N2BEndianRect(a)    SwapRect(a)             
  166. #define B2NEndianRect(a)    SwapRect(a)
  167. #define N2LEndianRect(a)
  168. #define L2NEndianRect(a)             
  169.  
  170.  
  171.  
  172. #else
  173.  
  174. #define L2NEndianS16(a)                SwapS16(a)
  175. #define L2NEndianU16(a)                SwapU16(a)
  176.  
  177. #define L2NEndianS32(a)                SwapS32(a)
  178. #define L2NEndianU32(a)                SwapU32(a)
  179.  
  180. #define B2NEndianS16(a)                
  181. #define B2NEndianU16(a)                
  182.  
  183. #define B2NEndianS32(a)                
  184. #define B2NEndianU32(a)                
  185.  
  186. #define N2BEndianS32    B2NEndianS32
  187. #define N2BEndianU32    B2NEndianU32
  188.  
  189. #define N2LEndianS32    L2NEndianS32
  190. #define N2LEndianU32    L2NEndianU32
  191.  
  192. #define N2BEndianS16    B2NEndianS16
  193. #define N2BEndianU16    B2NEndianU16
  194.  
  195. #define N2LEndianS16    L2NEndianS16
  196. #define N2LEndianU16    L2NEndianU16
  197.  
  198. #define L2NEndianS16Multiple(a,b)    SwapS16Multiple(a,b)
  199. #define L2NEndianU16Multiple(a,b)    SwapU16Multiple(a,b)
  200.  
  201. #define L2NEndianS32Multiple(a,b)    SwapS32Multiple(a,b)    
  202. #define L2NEndianU32Multiple(a,b)    SwapU32Multiple(a,b)    
  203.  
  204. #define B2NEndianS16Multiple(a,b)
  205. #define B2NEndianU16Multiple(a,b)
  206.  
  207. #define B2NEndianS32Multiple(a,b)
  208. #define B2NEndianU32Multiple(a,b)
  209.  
  210. #define N2BEndianMatrix3by3(a)
  211. #define B2NEndianMatrix3by3(a)
  212. #define N2LEndianMatrix3by3(a)    SwapMatrix3by3(a)
  213. #define L2NEndianMatrix3by3(a)    SwapMatrix3by3(a)
  214.  
  215. #define N2BEndianRect(a)                
  216. #define B2NEndianRect(a)
  217. #define N2LEndianRect(a)    SwapRect(a) 
  218. #define L2NEndianRect(a)    SwapRect(a)
  219.  
  220. #endif
  221.  
  222.  
  223. // Macros that take big-endian data, and swap it to native (my) format.
  224. #if TARGET_RT_LITTLE_ENDIAN
  225.  
  226.     #define MyEndian16(a)        SwappedU16(a)
  227.     #define MyEndian32(a)        SwappedU32(a)
  228.     #define MyEndianS16(a)        SwappedS16(a)
  229.     #define MyEndianS32(a)        SwappedS32(a)
  230.  
  231.     #define MyEndianRect(a)        SwapRect(a)    
  232.  
  233.     #define MyEndianPoint(a)    SwapU16((a).v);   SwapU16((a).h)
  234.     #define MyEndianRGBColor(a) SwapU16((a).red); SwapU16((a).green);  SwapU16((a).blue); 
  235.  
  236.     #define MyEndian16Multiple(p, num) SwapU16Multiple(p,num)
  237.     #define MyEndian32Multiple(p, num) SwapU32Multiple(p,num)
  238.  
  239.     #define MyEndianQTFloatDouble(a)    *(UInt64*)&a = Endian64_Swap(*(UInt64*)&a)
  240.     #define MyEndianQTFloatSingle(a)    *(UInt32*)&a = Endian32_Swap(*(UInt32*)&a)
  241.  
  242. #else
  243.     #define MyEndian16(a)        (a)
  244.     #define MyEndian32(a)        (a)
  245.     #define MyEndianS16(a)        (a)
  246.     #define MyEndianS32(a)        (a)
  247.  
  248.     #define MyEndianRect(a)                
  249.              
  250.     #define MyEndianPoint(a)    
  251.     #define MyEndianRGBColor(a)
  252.  
  253.     #define MyEndian16Multiple(p,num)
  254.     #define MyEndian32Multiple(p,num)
  255.  
  256.     #define MyEndianQTFloatDouble(a)
  257.     #define MyEndianQTFloatSingle(a)
  258. #endif
  259.  
  260.  
  261.  
  262. // Macros that take native expressions, and swap the result 
  263. // to the specified endian-ness.
  264. #if TARGET_RT_LITTLE_ENDIAN
  265.     #define LittleEndian16(a) (a)
  266.     #define LittleEndian32(a) (a)
  267.     #define BigEndian16(a) SwappedU16(a)
  268.     #define BigEndian32(a) SwappedU32(a)
  269.     
  270.     #define MyEndianFromLittle16(a) (a)
  271.     #define MyEndianFromLittle32(a) (a)
  272. #else
  273.     #define LittleEndian16(a) SwappedU16(a)
  274.     #define LittleEndian32(a) SwappedU32(a)
  275.     #define BigEndian16(a) (a)
  276.     #define BigEndian32(a) (a)
  277.     
  278.     #define MyEndianFromLittle16(a) SwappedU16(a)
  279.     #define MyEndianFromLittle32(a) SwappedU32(a)
  280. #endif
  281.  
  282.  
  283.  
  284. // Handy stream macros - reads and writes longs and shorts aligned and misaligned
  285.  
  286. // this was TARGET_OS_WIN32, but NeXTIntel wants this
  287. #if TARGET_RT_LITTLE_ENDIAN
  288. #define Get32(x)        (*(long*)(x))
  289. #define GetU32(x)        (*(unsigned long*)(x))
  290. #define Set32(x,y)        (*(long*)(x)) = ((long)(y))
  291.  
  292. #define Get16(x)        (*(short*)(x))
  293. #define GetU16(x)        (*(unsigned short*)(x))
  294. #define Set16(x,y)        (*(short*)(x)) = ((short)(y))
  295.  
  296. #define Get32E(x)        SwappedS32(*(unsigned long*)(x))
  297.  
  298. #define GetU32E(x)        SwappedU32(*(unsigned long*)(x))
  299.  
  300. #define Set32E(x,y)        { unsigned long z_z_val = y; *(unsigned long*)(x)=SwappedU32(z_z_val); }
  301.  
  302. #define Get16E(x)        SwappedS16(*(unsigned short*)(x))
  303.  
  304. #define GetU16E(x)        SwappedU16(*(unsigned short*)(x))
  305.  
  306. #define Set16E(x,y)        { unsigned short z_z_val = y; *(unsigned short*)(x)=SwappedU16(z_z_val); }
  307.  
  308. #define ABGRFLIP(zzz)
  309.  
  310.  
  311. #elif TARGET_OS_UNIX
  312.  
  313. #if TARGET_CPU_PPC
  314. #define GetU32(x)    (*(unsigned long*)(x))
  315. #define Get32(x)    (*(long*)(x))
  316. #define Set32(x,y)    (*(unsigned long*)(x) = (unsigned long)(y))
  317. #define Get16(x)    (*(short*)(x))
  318. #define GetU16(x)    (*(unsigned short*)(x))
  319. #define Set16(x,y)    (*(unsigned short*)(x) = (unsigned short)(y))
  320.  
  321.  
  322.  
  323. #else /* risc based - gonna buserr if we access misaligned data */
  324.  
  325. #define GetU32(x) (unsigned long) (            \
  326.         (((unsigned char*)(x))[0] << 24) |    \
  327.         (((unsigned char*)(x))[1] << 16) |    \
  328.         (((unsigned char*)(x))[2] << 8)  |    \
  329.         (((unsigned char*)(x))[3]) )
  330.  
  331. #define Get32(x) (long) (            \
  332.         (((unsigned char*)(x))[0] << 24) |    \
  333.         (((unsigned char*)(x))[1] << 16) |    \
  334.         (((unsigned char*)(x))[2] << 8)  |    \
  335.         (((unsigned char*)(x))[3]) )
  336.  
  337. #define Set32(x,y) { unsigned long z_z_val = y; \
  338.         ((unsigned char*)(x))[0] = (z_z_val & 0xff000000) >> 24;                \
  339.         ((unsigned char*)(x))[1] = (z_z_val & 0x00ff0000) >> 16;                \
  340.         ((unsigned char*)(x))[2] = (z_z_val & 0x0000ff00) >> 8;                 \
  341.         ((unsigned char*)(x))[3] = (z_z_val & 0x000000ff);        }             \
  342.         
  343. #define Get16(x)    (short)    (    \
  344.         (((unsigned char*)(x))[0] << 8)  |    \
  345.         (((unsigned char*)(x))[1]) )
  346.  
  347. #define GetU16(x)    (unsigned short)    (    \
  348.         (((unsigned char*)(x))[0] << 8)  |    \
  349.         (((unsigned char*)(x))[1]) )
  350.  
  351. #define Set16(x,y) { unsigned long z_z_val = y; \
  352.         ((unsigned char*)(x))[0] = (z_z_val & 0xff00) >> 8;                 \
  353.         ((unsigned char*)(x))[1] = (z_z_val & 0x00ff);        }             \
  354.  
  355. #endif     /* non-ppc risc UNIX */
  356.  
  357. #define Get32E    Get32
  358. #define GetU32E    GetU32
  359. #define Set32E    Set32
  360.  
  361. #define Get16E    Get16
  362. #define GetU16E    GetU16
  363. #define Set16E    Set16
  364.  
  365. #define ABGRFLIP(zzz) { long zzzpix = zzz; zzz = zzz & 0xff00ff00;    \
  366.                         zzz |= ((zzzpix & 0x00ff0000) >> 16);        \
  367.                         zzz |= ((zzzpix & 0x000000ff) << 16); }
  368.  
  369.  
  370.  
  371. #else        /* not little-endian, not UNIX, must be MacOS - big endian */
  372.  
  373. #define Get32(x)        (*(long*)(x))
  374. #define GetU32(x)        (*(unsigned long*)(x))
  375. #define Set32(x,y)        (*(long*)(x)) = ((long)(y))
  376.  
  377. #define Get16(x)        (*(short*)(x))
  378. #define GetU16(x)        (*(unsigned short*)(x))
  379. #define Set16(x,y)        (*(short*)(x)) = ((short)(y))
  380.  
  381. #define Get32E    Get32
  382. #define GetU32E    GetU32
  383. #define Set32E    Set32
  384.  
  385. #define Get16E    Get16
  386. #define GetU16E    GetU16
  387. #define Set16E    Set16
  388.  
  389. #define ABGRFLIP(zzz)
  390.  
  391. #endif
  392.  
  393. long    FlipLongPtr        (long*);
  394. long    FlipShortPtr       (short*);
  395. void    FlipE80            (void *);
  396. void    FlipArray          (void *,long,short);
  397.  
  398.  
  399.  
  400. #if !TARGET_OS_MAC && TARGET_RT_LITTLE_ENDIAN
  401. #ifndef RgnHandle
  402.     #include <Quickdraw.h>
  403. #endif
  404. void B2NEndianRgnHandle(RgnHandle theRgn);
  405. void N2BEndianRgnHandle(RgnHandle theRgn);
  406. void B2NEndianPixMapHandle(PixMapHandle thePixMap);
  407. void N2BEndianPixMapHandle(PixMapHandle thePixMap);
  408. #endif
  409.  
  410.  
  411.  
  412. /*
  413.     Conversion macros for BigEndian always types (QuickTimeMusic.h)
  414. */
  415. #define GetNativeLongFrom(p)                (long)Get32E(p)
  416. #define GetNativeShortFrom(p)                (short)Get16E(p)
  417. #define GetNativeFixedFrom(p)                (Fixed)Get32E(p)
  418. #define GetNativeUnsignedFixedFrom(p)        (UnsignedFixed)Get32E(p)
  419. #define GetNativeOSTypeFrom(p)                (OSType)Get32E(p)
  420. #define SetBigEndianLongAt(p, val)            Set32E(p, val)
  421. #define SetBigEndianShortAt(p, val)            Set16E(p, val)
  422. #define SetBigEndianFixedAt(p, val)            Set32E(p, val)
  423. #define SetBigEndianUnsignedFixedAt(p, val)    Set32E(p, val)
  424. #define SetBigEndianOSTypeAt(p, val)        Set32E(p, val)
  425.  
  426.  
  427.  
  428. #if PRAGMA_STRUCT_ALIGN
  429.     #pragma options align=reset
  430. #elif PRAGMA_STRUCT_PACKPUSH
  431.     #pragma pack(pop)
  432. #elif PRAGMA_STRUCT_PACK
  433.     #pragma pack()
  434. #endif
  435.  
  436. #ifdef PRAGMA_IMPORT_OFF
  437. #pragma import off
  438. #elif PRAGMA_IMPORT
  439. #pragma import reset
  440. #endif
  441.  
  442. #ifdef __cplusplus
  443. }
  444. #endif
  445.  
  446. // DNC: End EndianPriv.h
  447.  
  448. // DNC: Start BltTrans.h
  449.  
  450. #define from32wxyzto32xyzw(a)        a = ((((a)&0xffffff)<<8) | ((((unsigned long)(a))&0xff000000)>>24))
  451. #define from32wxyzto32wzyx(a)        a = ((((a)&0xff)<<16) | (((a)&0xff0000)>>16) | ((((unsigned long)(a))&0xff00ff00)))
  452. #define from32wxyzto32yxwz(a)        a = ((((a)&0xff00)<<16) | (((a)&0xff000000)>>16) | ((((unsigned long)(a))&0xff00ff)))
  453. #define from32wxyzto32zwxy(a)        a = ((((a)&0xffffff00)>>8) | ((((unsigned long)(a))&0xff)<<24))
  454. #define from32wxyzto32xwzy(a)        a = ((((a)&0xff00ff00)>>8) | ((((unsigned long)(a))&0x00ff00ff)<<8))
  455. #define from32wxyzto32zyxw(a)        a = ((((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)&0xff0000)>>8) | ((((unsigned long)(a))&0xff000000)>>24))
  456. #define from32wxyzto32yzwx(a)        a = ((((a)&0xffff0000)>>16) | ((((unsigned long)(a))&0x0000ffff)<<16))
  457.  
  458. #define from32wxyzto32wxy_(a)        a = ((unsigned long)(a) & 0xffffff00)
  459. #define from32wxyzto32_xyz(a)        a = ((unsigned long)(a) & 0x00ffffff)
  460. #define from32wxyzto32_yxw(a)        a = ((((a)&0xff00)<<8) | (((a)&0xff0000)>>8) | ((((unsigned long)(a))&0xff000000)>>24))
  461. #define from32wxyzto32zyx_(a)        a = ((((a)&0xff)<<24) | (((a)&0xff00)<<8) | ((((unsigned long)(a))&0xff0000)>>8))
  462. #define from32wxyzto32yxw_(a)        a = ((((a)&0xff00)<<16) | (((a)&0xff000000)>>16) | ((((unsigned long)(a))&0xff0000))) 
  463. #define from32wxyzto32_zyx(a)        a = ((((a)&0xff)<<16) | (((a)&0xff0000)>>16) | ((((unsigned long)(a))&0x0000ff00)))
  464. #define from32wxyzto32_wxy(a)        a = (((((unsigned long)(a))&0xffffff00)>>8))
  465. #define from32wxyzto32xyz_(a)        a = (((((unsigned long)(a))&0xffffff)<<8))
  466.  
  467. #define from32ARGBto32ABGR(a)        from32wxyzto32wzyx(a)
  468. #define from32ARGBto32BGRA(a)        from32wxyzto32zyxw(a)
  469. #define from32ARGBto32RGBA(a)        from32wxyzto32xyzw(a)
  470.  
  471. #define from32ABGRto32ARGB(a)        from32wxyzto32wzyx(a)
  472. #define from32ABGRto32BGRA(a)        from32wxyzto32xyzw(a)
  473. #define from32ABGRto32RGBA(a)        from32wxyzto32zyxw(a)
  474.  
  475. #define from32BGRAto32ARGB(a)        from32wxyzto32zyxw(a)
  476. #define from32BGRAto32ABGR(a)        from32wxyzto32zwxy(a)
  477. #define from32BGRAto32RGBA(a)        from32wxyzto32yxwz(a)
  478.  
  479. #define from32RGBAto32ARGB(a)        from32wxyzto32zwxy(a)
  480. #define from32RGBAto32ABGR(a)        from32wxyzto32zyxw(a)
  481. #define from32RGBAto32BGRA(a)        from32wxyzto32yxwz(a)
  482.  
  483. // 16 bit
  484. #define fromBERGBx2toLERGBx2(a)        from32wxyzto32xwzy(a)
  485. #define fromBERGBx2toLE565x2(a)        a = ((((a)&0x007f007f)<<9) | (((a)&0x3f003f00)>>8) | ((((unsigned long)(a))&0xe000e000)>>7))
  486.  
  487. #define fromLERGBx2toBERGBx2(a)        from32wxyzto32xwzy(a)
  488. #define fromLERGBx2toLE565x2(a)        a = ((((a)&0x007f007f)<<1) | (((a)&0x80008000)>>15) | (((a)&0x60006000)<<1) | ((((unsigned long)(a))&0x3f003f00)))    
  489.  
  490. #define fromLE565x2toLERGBx2(a)        a = ((((a)&0x1f001f00)) | (((a)&0xc0fec0fe)>>1) | ((((unsigned long)(a))&0x00010001)<<15))    
  491. #define fromLE565x2toBERGBx2(a)        a = ((((a)&0x00ff00ff)<<7) | (((a)&0x1f001f00)>>8) | ((((unsigned long)(a))&0xc000c000)>>9))    
  492.  
  493.  
  494. // DNC: End BltTrans.h
  495.  
  496. #define TempAllowDebugCalls    1
  497.  
  498. #define Flip24(data) { \
  499.     data = ( ( ( data & 0x0000ff ) << 16 ) | ( ( data & 0xff0000 ) >> 16 ) | ( data & 0x00ff00 ) ); \
  500. }
  501.  
  502. #define Set24(dst,data) { \
  503.     *(unsigned char *)(dst) = (data & 0xff0000) >> 16; \
  504.     *((unsigned char *)(dst)+1) = (data & 0xff00) >> 8; \
  505.     *((unsigned char *)(dst)+2) = data & 0xff; \
  506. }
  507.  
  508. #define Get24(src)        ( ( ((unsigned long)(((unsigned char *)src)[0])) << 16    ) + \
  509.                           ( ((unsigned long)(((unsigned char *)src)[1])) << 8    ) + \
  510.                             ((unsigned long)(((unsigned char *)src)[2]))        )
  511.  
  512. #undef cnv16Nto16DPF
  513. #if dstIs16BE555                                        // don't flip in either case
  514. #define cnv16Nto16DPF(a)        
  515. #elif dstIs16LE555                                    // flip in both cases
  516. #define cnv16Nto16DPF(a)        SwapU16(a)
  517. #elif dstIs16LE565                //            r+g1                g2n+b                                g2
  518. #define cnv16Nto16DPF(a)        a = ((((a)&0x007f)<<9) | (((a)&0x3f00)>>8) | (((unsigned short)(a)&0xe000)>>7))
  519. #else
  520.     #if TempAllowDebugCalls
  521.         #define cnv16Nto16DPF(a)        DebugStr("\pcnv16Nto16DPF")
  522.     #else
  523.         #error "cnv16Nto16DPF(a) not defined for this case in BltMacros.h";
  524.     #endif
  525. #endif
  526.  
  527. #undef cnv16RGto16DPF
  528. #if dstIs16BE555
  529. #define cnv16RGto16DPF(a)    N2BEndianU16(a)
  530. #elif dstIs16LE555
  531. #define cnv16RGto16DPF(a)    N2LEndianU16(a)    
  532. #elif dstIs16LE565                //            r+g1+g2                                g2n+b
  533. #define cnv16RGto16DPF(a)    a = ((((a)&0x7fe0)<<1) | ((((unsigned short)(a))&0x003f)) )
  534. #else
  535.     #if TempAllowDebugCalls
  536.         #define cnv16RGto16DPF(a)    DebugStr("\pcnv16RGto16DPF")
  537.     #else
  538.         #error "cnv16RGto16DPF(a) not defined for this case in BltMacros.h";
  539.     #endif
  540. #endif
  541.  
  542. #undef cnv16DPFto16RG
  543. #if dstIs16BE555
  544. #define cnv16DPFto16RG(a)    B2NEndianU16(a)
  545. #elif dstIs16LE555
  546. #define cnv16DPFto16RG(a)    L2NEndianU16(a)    
  547. #elif dstIs16LE565 & TARGET_RT_LITTLE_ENDIAN                //            r+g1+g2                                g2n+b
  548. #define cnv16DPFto16RG(a)    a = ((((a)&0xffc0)>>1) | ((((unsigned short)(a))&0x001f)) )
  549. #else
  550.     #if TempAllowDebugCalls
  551.         #define cnv16DPFto16RG(a)    DebugStr("\pcnv16DPFto16RG")
  552.     #else
  553.         #error "cnv16DPFto16RG(a) not defined for this case in BltMacros.h";
  554.     #endif
  555. #endif
  556.  
  557. #undef cnv16Nx2to16DPFx2
  558. #if dstIs16BE555                                        // don't flip in either case
  559. #define cnv16Nx2to16DPFx2(a)        
  560. #elif dstIs16LE555 & TARGET_RT_LITTLE_ENDIAN
  561. #define cnv16Nx2to16DPFx2(a)        from32wxyzto32xwzy(a)
  562. #elif dstIs16LE555 & !TARGET_RT_LITTLE_ENDIAN
  563. #define cnv16Nx2to16DPFx2(a)        from32wxyzto32yzwx(a)
  564. #elif dstIs16LE565                    //            r+g1                    g2n+b                                    g2                                    g2->g1
  565. #define cnv16Nx2to16DPFx2(a)        a = ((((a)&0x007f007f)<<9) | (((a)&0x3f003f00)>>8) | ((((unsigned long)(a))&0xe000e000)>>7))
  566. #else
  567.     #if TempAllowDebugCalls
  568.         #define cnv16Nx2to16DPFx2(a)        DebugStr("\pcnv16Nx2to16DPFx2")
  569.     #else
  570.         #error "cnv16Nx2to16DPFx2(a) not defined for this case in BltMacros.h";
  571.     #endif
  572. #endif
  573.  
  574. #undef cnv16RGx2to16DPFx2
  575. #if dstIs16BE555
  576. #define cnv16RGx2to16DPFx2(a)        N2BEndianU32(a)
  577. #elif dstIs16LE555 & TARGET_RT_LITTLE_ENDIAN
  578. #define cnv16RGx2to16DPFx2(a)        from32wxyzto32yzwx(a)
  579. #elif dstIs16LE555 & !TARGET_RT_LITTLE_ENDIAN
  580. #define cnv16RGx2to16DPFx2(a)        DebugStr("\pcnv16RGx2to16DPFx2")
  581. #elif dstIs16LE565                    //            r+g1+g2                    g2n+b                            r2+g3+g4                    g4n+b2                                    g2                                    
  582. #define cnv16RGx2to16DPFx2(a)        a = ((((a)&0x7fe00000)>>15) | (((a)&0x003f0000)>>16) | (((a)&0x00007fe0)<<17) | ((((unsigned long)(a))&0x0000003f)<<16))
  583. #else
  584.     #if TempAllowDebugCalls
  585.         #define cnv16RGx2to16DPFx2(a)        DebugStr("\pcnv16rGx2to16DPFx2")
  586.     #else
  587.         #error "cnv16RGx2to16DPFx2(a) not defined for this case in BltMacros.h";
  588.     #endif
  589. #endif
  590.  
  591. #undef cnv16DPFx2to16RGx2
  592. #if dstIs16BE555
  593. #define cnv16DPFx2to16RGx2(a)        B2NEndianU32(a)
  594. #elif dstIs16LE555 & TARGET_RT_LITTLE_ENDIAN
  595. #define cnv16DPFx2to16RGx2(a)        from32wxyzto32yzwx(a)
  596. #elif dstIs16LE555 & !TARGET_RT_LITTLE_ENDIAN
  597. #define cnv16DPFx2to16RGx2(a)        from32wxyzto32xwzy(a)
  598. #elif dstIs16LE565                    //            r+g1+g2                    g2n+b                            r2+g3+g4                    g4n+b2                                    g2                                    
  599. #define cnv16DPFx2to16RGx2(a)        a = ((((a)&0xffc00000)>>17) | (((a)&0x001f0000)>>16) | (((a)&0x0000ffc0)<<15) | ((((unsigned long)(a))&0x0000001f)<<16))
  600. #else
  601.     #if TempAllowDebugCalls
  602.         #define cnv16DPFx2to16RGx2(a)        DebugStr("\pcnv16DPFx2to16RGx2")
  603.     #else
  604.         #error "cnv16DPFx2to16RGx2(a) not defined for this case in BltMacros.h";
  605.     #endif
  606. #endif
  607.  
  608. #undef cnv16SPFx2to16RGx2
  609. #if srcIs16BE555
  610. #define cnv16SPFx2to16RGx2(a)        B2NEndianU32(a)
  611. #elif srcIs16LE555 & TARGET_RT_LITTLE_ENDIAN
  612. #define cnv16SPFx2to16RGx2(a)        from32wxyzto32yzwx(a)
  613. #elif srcIs16LE555 & !TARGET_RT_LITTLE_ENDIAN
  614. #define cnv16SPFx2to16RGx2(a)        from32wxyzto32xwzy(a)
  615. #elif srcIs16LE565                    //            r+g1+g2                    g2n+b                            r2+g3+g4                    g4n+b2                                    g2                                    
  616. #define cnv16SPFx2to16RGx2(a)        a = ((((a)&0xffc00000)>>17) | (((a)&0x001f0000)>>16) | (((a)&0x0000ffc0)<<15) | ((((unsigned long)(a))&0x0000001f)<<16))
  617. #else
  618.     #if TempAllowDebugCalls
  619.         #define cnv16SPFx2to16RGx2(a)        DebugStr("\pcnv16SPFx2to16RGx2")
  620.     #else
  621.         #error "cnv16SPFx2to16RGx2(a) not defined for this case in BltMacros.h";
  622.     #endif
  623. #endif
  624.  
  625. // converts 32bit argb to selected pixel format
  626. #undef cnv32ARto32PF
  627. #define cnv32ARto32PF cnv32ARto32DPF
  628. #undef cnv32ARto32DPF
  629. #if dstIs32ARGB
  630. #define cnv32ARto32DPF(a)        N2BEndianU32(a)
  631. #elif dstIs32BGRA
  632. #define cnv32ARto32DPF(a)        N2LEndianU32(a)
  633. #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  634. #define cnv32ARto32DPF(a)        from32wxyzto32xyzw(a)
  635. #elif dstIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  636. #define cnv32ARto32DPF(a)        from32wxyzto32wzyx(a)
  637. #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  638. #define cnv32ARto32DPF(a)        from32wxyzto32wzyx(a)
  639. #elif dstIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  640. #define cnv32ARto32DPF(a)        from32wxyzto32xyzw(a)
  641. #else
  642.     #if TempAllowDebugCalls
  643.         #define cnv32ARto32DPF(a)        DebugStr("\pcnv32ARto32DPF")
  644.     #else
  645.         #error "cnv32ARto32DPF(a) not defined for this case in BltMacros.h";
  646.     #endif
  647. #endif
  648.  
  649. // converts 32bit argb to selected pixel format
  650.  
  651. #undef cnv32PFto32AR
  652. #define cnv32PFto32AR cnv32DPFto32AR                // for compatibility
  653. #undef cnv32DPFto32AR
  654. #if dstIs32ARGB
  655. #define cnv32DPFto32AR(a)        B2NEndianU32(a)
  656. #elif dstIs32BGRA
  657. #define cnv32DPFto32AR(a)        L2NEndianU32(a)
  658. #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  659. #define cnv32DPFto32AR(a)        from32wxyzto32zwxy(a)
  660. #elif dstIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  661. #define cnv32DPFto32AR(a)        from32wxyzto32wzyx(a)
  662. #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  663. #define cnv32DPFto32AR(a)        from32wxyzto32wzyx(a)
  664. #elif dstIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  665. #define cnv32DPFto32AR(a)        from32wxyzto32zwxy(a)
  666. #else
  667.     #if TempAllowDebugCalls
  668.         #define cnv32DPFto32AR(a)        DebugStr("\pcnv32DPFto32AR")
  669.     #else
  670.         #error "cnv32DPFto32AR(a) not defined for this case in BltMacros.h";
  671.     #endif
  672. #endif
  673.  
  674. // converts argb(BE)/bgra(LE) to to selected pixel format
  675. #undef cnv32Nto32PF
  676. #if dstIs32ARGB
  677. #define cnv32Nto32PF(a)        
  678. #elif dstIs32BGRA
  679. #define cnv32Nto32PF(a)        from32wxyzto32zyxw(a)
  680. #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  681. #define cnv32Nto32PF(a)        from32wxyzto32yxwz(a)
  682. #elif dstIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  683. #define cnv32Nto32PF(a)        from32wxyzto32wzyx(a)
  684. #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  685. #define cnv32Nto32PF(a)        from32wxyzto32zwxy(a)
  686. #elif dstIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  687. #define cnv32Nto32PF(a)        from32wxyzto32xyzw(a)
  688. #else
  689.     #if TempAllowDebugCalls
  690.         #define cnv32Nto32PF(a)        DebugStr("\pcnv32Nto32PF")
  691.     #else
  692.         #error "cnv32Nto32PF(a) not defined for this case in BltMacros.h";
  693.     #endif
  694. #endif
  695.  
  696. // converts _rgb(BE)/bgr_(LE) to to selected pixel format
  697. #undef cnv24Nto32PF
  698. #if dstIs32ARGB && TARGET_RT_LITTLE_ENDIAN
  699. #define cnv24Nto32PF(a)        from32wxyzto32wxy_(a)
  700. #elif dstIs32ARGB && !TARGET_RT_LITTLE_ENDIAN
  701. #define cnv24Nto32PF(a)        from32wxyzto32_xyz(a)
  702. #elif dstIs32BGRA && TARGET_RT_LITTLE_ENDIAN                
  703. #define cnv24Nto32PF(a)        from32wxyzto32_yxw(a)
  704. #elif dstIs32BGRA && !TARGET_RT_LITTLE_ENDIAN                
  705. #define cnv24Nto32PF(a)        from32wxyzto32zyx_(a)
  706. #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  707. #define cnv24Nto32PF(a)        from32wxyzto32yxw_(a)
  708. #elif dstIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  709. #define cnv24Nto32PF(a)        from32wxyzto32_zyx(a)
  710. #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  711. #define cnv24Nto32PF(a)        from32wxyzto32_wxy(a)
  712. #elif dstIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  713. #define cnv24Nto32PF(a)        from32wxyzto32xyz_(a)
  714. #else
  715.     #if TempAllowDebugCalls
  716.         #define cnv24Nto32PF(a)        DebugStr("\pcnv24Nto32PF")
  717.     #else
  718.         #error "cnv24Nto32PF(a) not defined for this case in BltMacros.h";
  719.     #endif
  720. #endif
  721.  
  722. // Transfer long from ARGB to selected pixel format
  723. #undef T32Nto32PF
  724. #if dstIs32ARGB || dstIs32BGRA || dstIs32ABGR || dstIs32RGBA
  725. #define T32Nto32PF(src,dst) { unsigned long temp = GetU32(src); cnv32Nto32PF(temp); Set32(dst,temp); }
  726. #else
  727.     #if TempAllowDebugCalls
  728.         #define T32Nto32PF(src,dst) \
  729.             DebugStr("\pT32Nto32PF")
  730.     #else
  731.         #error "T32Nto32PF(src,dst) not defined for this case in BltMacros.h";
  732.     #endif
  733. #endif
  734.  
  735. // Transfer long from ARGB to selected pixel format, post increment pointers
  736. #undef T32NIto32PFI
  737. #if dstIs32ARGB || dstIs32BGRA || dstIs32ABGR || dstIs32RGBA
  738. #define T32NIto32PFI(src,dst) { unsigned long temp = GetU32(src); cnv32Nto32PF(temp); Set32(dst,temp); dst++; src++;}
  739. #else
  740.     #if TempAllowDebugCalls
  741.         #define T32NIto32PFI(src,dst) \
  742.             DebugStr("\pT32NIto32PFI")
  743.     #else
  744.         #error "T32NIto32PFI(src,dst) not defined for this case in BltMacros.h";
  745.     #endif
  746. #endif
  747.  
  748. // Set long, convert ARGB to selected pixel format
  749. #undef Set32ARtoPF
  750. #if dstIs32ARGB || dstIs32BGRA || dstIs32ABGR || dstIs32RGBA
  751. #define Set32ARtoPF(dst,dstdata) \
  752. { \
  753.     unsigned long temp = dstdata; \
  754.     cnv32ARto32PF(temp); \
  755.     Set32(dst,temp); \
  756. }
  757. #else
  758.     #if TempAllowDebugCalls
  759.         #define Set32ARtoPF(dst,dstdata) \
  760.             DebugStr("\pSet32ARtoPF")
  761.     #else
  762.         #error "Set32ARtoPF(dst,dstdata) not defined for this case in BltMacros.h";
  763.     #endif
  764. #endif
  765.  
  766.  
  767. // converts 32 src pixel format to 32 dst pixel format, assumes src and dst will be read and written using Get32 and Set32
  768. #undef cnv32SPFto32DPF
  769. #if srcIs32ARGB
  770.     #if TARGET_RT_LITTLE_ENDIAN
  771.         #if dstIs32ARGB
  772.             #define cnv32SPFto32DPF(a)
  773.         #elif dstIs32BGRA
  774.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  775.         #elif dstIs32ABGR
  776.             #define cnv32SPFto32DPF(a)        from32wxyzto32yxwz(a)
  777.         #elif dstIs32RGBA
  778.             #define cnv32SPFto32DPF(a)        from32wxyzto32zwxy(a)
  779.         #else
  780.             #if TempAllowDebugCalls
  781.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  782.             #else
  783.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  784.             #endif
  785.         #endif
  786.     #else            // BIG_ENDIAN
  787.         #if dstIs32ARGB
  788.             #define cnv32SPFto32DPF(a)
  789.         #elif dstIs32BGRA
  790.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  791.         #elif dstIs32ABGR
  792.             #define cnv32SPFto32DPF(a)        from32wxyzto32wzyx(a)
  793.         #elif dstIs32RGBA
  794.             #define cnv32SPFto32DPF(a)        from32wxyzto32xyzw(a)
  795.         #else
  796.             #if TempAllowDebugCalls
  797.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  798.             #else
  799.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  800.             #endif
  801.         #endif
  802.     #endif
  803. #elif srcIs32BGRA
  804.     #if TARGET_RT_LITTLE_ENDIAN
  805.         #if dstIs32ARGB
  806.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  807.         #elif dstIs32BGRA
  808.             #define cnv32SPFto32DPF(a)        
  809.         #elif dstIs32ABGR
  810.             #define cnv32SPFto32DPF(a)        from32wxyzto32xyzw(a)
  811.         #elif dstIs32RGBA
  812.             #define cnv32SPFto32DPF(a)        from32wxyzto32wzyx(a)
  813.         #else
  814.             #if TempAllowDebugCalls
  815.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  816.             #else
  817.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  818.             #endif
  819.         #endif
  820.     #else            // TARGET_RT_BIG_ENDIAN
  821.         #if dstIs32ARGB
  822.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  823.         #elif dstIs32BGRA
  824.             #define cnv32SPFto32DPF(a)        
  825.         #elif dstIs32ABGR
  826.             #define cnv32SPFto32DPF(a)        from32wxyzto32zwxy(a)
  827.         #elif dstIs32RGBA
  828.             #define cnv32SPFto32DPF(a)        from32wxyzto32yxwz(a)
  829.         #else
  830.             #if TempAllowDebugCalls
  831.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  832.             #else
  833.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  834.             #endif
  835.         #endif
  836.     #endif
  837. #elif srcIs32ABGR
  838.     #if TARGET_RT_LITTLE_ENDIAN
  839.         #if dstIs32ARGB
  840.             #define cnv32SPFto32DPF(a)        from32wxyzto32yxwz(a)
  841.         #elif dstIs32BGRA
  842.             #define cnv32SPFto32DPF(a)        from32wxyzto32zwxy(a)
  843.         #elif dstIs32ABGR
  844.             #define cnv32SPFto32DPF(a)        
  845.         #elif dstIs32RGBA
  846.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  847.         #else
  848.             #if TempAllowDebugCalls
  849.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  850.             #else
  851.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  852.             #endif
  853.         #endif
  854.     #else        // TARGET_RT_BIG_ENDIAN
  855.         #if dstIs32ARGB
  856.             #define cnv32SPFto32DPF(a)        from32wxyzto32wzyx(a)
  857.         #elif dstIs32BGRA
  858.             #define cnv32SPFto32DPF(a)        from32wxyzto32xyzw(a)
  859.         #elif dstIs32ABGR
  860.             #define cnv32SPFto32DPF(a)        
  861.         #elif dstIs32RGBA
  862.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  863.         #else
  864.             #if TempAllowDebugCalls
  865.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  866.             #else
  867.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  868.             #endif
  869.         #endif
  870.     #endif
  871. #elif srcIs32RGBA
  872.     #if TARGET_RT_LITTLE_ENDIAN
  873.         #if dstIs32ARGB
  874.             #define cnv32SPFto32DPF(a)        from32wxyzto32xyzw(a)
  875.         #elif dstIs32BGRA
  876.             #define cnv32SPFto32DPF(a)        from32wxyzto32wzyx(a)
  877.         #elif dstIs32ABGR
  878.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  879.         #elif dstIs32RGBA
  880.             #define cnv32SPFto32DPF(a)        
  881.         #else
  882.             #if TempAllowDebugCalls
  883.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  884.             #else
  885.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  886.             #endif
  887.         #endif
  888.     #else            //  TARGET_RT_BIG_ENDIAN
  889.         #if dstIs32ARGB
  890.             #define cnv32SPFto32DPF(a)        from32wxyzto32zwxy(a)
  891.         #elif dstIs32BGRA
  892.             #define cnv32SPFto32DPF(a)        from32wxyzto32yxwz(a)
  893.         #elif dstIs32ABGR
  894.             #define cnv32SPFto32DPF(a)        SwapU32(a)
  895.         #elif dstIs32RGBA
  896.             #define cnv32SPFto32DPF(a)        
  897.         #else
  898.             #if TempAllowDebugCalls
  899.                 #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  900.             #else
  901.                 #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  902.             #endif
  903.         #endif
  904.     #endif
  905. #else
  906.     #if TempAllowDebugCalls
  907.         #define cnv32SPFto32DPF(a)    DebugStr("\pcnv32SPFto32DPF")
  908.     #else
  909.         #error "cnv32SPFto32DPF(a) not defined for this case in BltMacros.h";
  910.     #endif
  911. #endif
  912.  
  913. #undef T32SPFto32DPF
  914. #if ( ( dstIs32ARGB || dstIs32BGRA || dstIs32ABGR || dstIs32RGBA ) && ( srcIs32ARGB || srcIs32BGRA || srcIs32ABGR || srcIs32RGBA ))
  915. #define T32SPFto32DPF(src,dst) { unsigned long temp = GetU32(src); cnv32SPFto32DPF(temp); Set32(dst,temp); }
  916. #else
  917.     #if TempAllowDebugCalls
  918.         #define T32SPFto32DPF(src,dst) { DebugStr("\pT32SPFto32DPF"); }
  919.     #else
  920.         #error "T32SPFto32DPF(src,dst) not defined for this case in BltMacros.h";
  921.     #endif
  922. #endif
  923.  
  924. // converts 16 src pixel format to 16 dst pixel format, assumes src and dst will be read and written using Get16 and Set16
  925. #undef cnv16SPFto16DPF
  926. #undef cnv16SPFequals16DPF
  927. #if srcIs16BE555
  928.     #if dstIs16BE555
  929.         #define cnv16SPFto16DPF(a)
  930.         #define cnv16SPFequals16DPF 1
  931.     #elif dstIs16LE555
  932.         #define cnv16SPFto16DPF(a)        SwapU16(a)
  933.     #elif dstIs16LE565
  934.         #define cnv16SPFto16DPF(a)        a = ((((a)&0x007f)<<9) | (((a)&0x3f00)>>8) | (((unsigned short)(a)&0xe000)>>7))
  935.     #else
  936.         #if TempAllowDebugCalls
  937.             #define cnv16SPFto16DPF(a)    DebugStr("\pcnv16SPFto16DPF")
  938.         #else
  939.             #error "cnv16SPFto16DPF(a) not defined for this case in BltMacros.h";
  940.         #endif
  941.     #endif
  942. #elif srcIs16LE555 && TARGET_RT_LITTLE_ENDIAN
  943.     #if dstIs16BE555
  944.         #define cnv16SPFto16DPF(a)        SwapU16(a)
  945.     #elif dstIs16LE555
  946.         #define cnv16SPFto16DPF(a)        
  947.         #define cnv16SPFequals16DPF 1
  948.     #elif dstIs16LE565
  949.         #define cnv16SPFto16DPF(a)        a = ((((a)&0x7fe0)<<1) | ((((unsigned short)(a))&0x003f)) )
  950.     #else
  951.         #if TempAllowDebugCalls
  952.             #define cnv16SPFto16DPF(a)    DebugStr("\pcnv16SPFto16DPF")
  953.         #else
  954.             #error "cnv16SPFto16DPF(a) not defined for this case in BltMacros.h";
  955.         #endif
  956.     #endif
  957. #elif srcIs16LE565 && TARGET_RT_LITTLE_ENDIAN
  958.     #if dstIs16BE555
  959.         #define cnv16SPFto16DPF(a)        a = ((((a)&0xff00)>>9) | (((a)&0x01e0)<<7) | ((((unsigned short)(a))&0x001f)<<8) )
  960.     #elif dstIs16LE555
  961.         #define cnv16SPFto16DPF(a)        a = ((((a)&0xffe0)>>1) | ((((unsigned short)(a))&0x001f)) )
  962.     #elif dstIs16LE565
  963.         #define cnv16SPFto16DPF(a)        
  964.         #define cnv16SPFequals16DPF 1
  965.     #else
  966.         #if TempAllowDebugCalls
  967.             #define cnv16SPFto16DPF(a)    DebugStr("\pcnv16SPFto16DPF")
  968.         #else
  969.             #error "cnv16SPFto16DPF(a) not defined for this case in BltMacros.h";
  970.         #endif
  971.     #endif
  972. #else
  973.     #if TempAllowDebugCalls
  974.         #define cnv16SPFto16DPF(a)    DebugStr("\pcnv16SPFto16DPF")
  975.     #else
  976.         #error "cnv16SPFto16DPF(a) not defined for this case in BltMacros.h";
  977.     #endif
  978. #endif
  979.  
  980. // converts 16x2 src pixel format to 16x2 dst pixel format, assumes src and dst will be read and written using Get32 and Set32
  981. #undef cnv16SPFx2to16DPFx2
  982. #if srcIs16BE555
  983.     #if dstIs16BE555
  984.         #define cnv16SPFx2to16DPFx2(a)
  985.     #elif dstIs16LE555
  986.         #define cnv16SPFx2to16DPFx2(a)        from32wxyzto32xwzy(a)
  987.     #elif dstIs16LE565
  988.         #define cnv16SPFx2to16DPFx2(a)        a = ((((a)&0x007f007f)<<9) | (((a)&0x3f003f00)>>8) | ((((unsigned long)(a))&0xe000e000)>>7))
  989.     #else
  990.         #if TempAllowDebugCalls
  991.             #define cnv16SPFx2to16DPFx2(a)    DebugStr("\pcnv16SPFx2to16DPFx2")
  992.             
  993.             #error "cnv16SPFx2to16DPFx2(a) not defined for this case in BltMacros.h";
  994.         #endif
  995.     #endif
  996. #elif srcIs16LE555 && TARGET_RT_LITTLE_ENDIAN
  997.     #if dstIs16BE555
  998.         #define cnv16SPFx2to16DPFx2(a)        from32wxyzto32xwzy(a)
  999.     #elif dstIs16LE555
  1000.         #define cnv16SPFx2to16DPFx2(a)        
  1001.     #elif dstIs16LE565
  1002.         #define cnv16SPFx2to16DPFx2(a)        a = ((((a)&0x7f007f00)>>7) | (((a)&0x003f003f)<<8) | ((((unsigned long)(a))&0x06000600)<<9))
  1003.     #else
  1004.         #if TempAllowDebugCalls
  1005.             #define cnv16SPFx2to16DPFx2(a)    DebugStr("\pcnv16SPFx2to16DPFx2")
  1006.         #else
  1007.             #error "cnv16SPFx2to16DPFx2(a) not defined for this case in BltMacros.h";
  1008.         #endif
  1009.     #endif
  1010. #elif srcIs16LE565 && TARGET_RT_LITTLE_ENDIAN
  1011.     #if dstIs16BE555
  1012.         #define cnv16SPFx2to16DPFx2(a)        a = ((((a)&0xfe00fe00)>>9) | (((a)&0x001f001f)<<8) | ((((unsigned long)(a))&0x01c001c0)<<7))
  1013.     #elif dstIs16LE555
  1014.         #define cnv16SPFx2to16DPFx2(a)        a = ((((a)&0xffc0ffc0)>>1) | ((((unsigned long)(a))&0x001f001f)))
  1015.     #elif dstIs16LE565
  1016.         #define cnv16SPFx2to16DPFx2(a)        
  1017.     #else
  1018.         #if TempAllowDebugCalls
  1019.             #define cnv16SPFx2to16DPFx2(a)    DebugStr("\pcnv16SPFx2to16DPFx2")
  1020.         #else
  1021.             #error "cnv16SPFx2to16DPFx2(a) not defined for this case in BltMacros.h";
  1022.         #endif
  1023.     #endif
  1024. #else
  1025.     #if TempAllowDebugCalls
  1026.         #define cnv16SPFx2to16DPFx2(a)    DebugStr("\pcnv16SPFx2to16DPFx2")
  1027.     #else
  1028.         #error "cnv16SPFx2to16DPFx2(a) not defined for this case in BltMacros.h";
  1029.     #endif
  1030. #endif
  1031.  
  1032. #undef cnv16SPFto16RG
  1033. #if srcIs16BE555
  1034. #define cnv16SPFto16RG(a)    B2NEndianU16(a)
  1035. #elif srcIs16LE555
  1036. #define cnv16SPFto16RG(a)    L2NEndianU16(a)    
  1037. #elif srcIs16LE565 & TARGET_RT_LITTLE_ENDIAN                //            r+g1+g2                                g2n+b
  1038. #define cnv16SPFto16RG(a)    a = ((((a)&0xffc0)>>1) | ((((unsigned short)(a))&0x001f)) )
  1039. #else
  1040.     #if TempAllowDebugCalls
  1041.         #define cnv16SPFto16RG(a)    DebugStr("\pcnv16SPFto16RG")
  1042.     #else
  1043.         #error "cnv16SPFto16RG(a) not defined for this case in BltMacros.h";
  1044.     #endif
  1045. #endif
  1046.  
  1047.  
  1048. #undef cnv16RGx2to16DPFx2
  1049. #if dstIs16BE555
  1050. #define cnv16RGx2to16DPFx2(a)        N2BEndianU32(a)
  1051. #elif dstIs16LE555 & TARGET_RT_LITTLE_ENDIAN
  1052. #define cnv16RGx2to16DPFx2(a)        from32wxyzto32yzwx(a)
  1053. #elif dstIs16LE555 & !TARGET_RT_LITTLE_ENDIAN
  1054.     #if TempAllowDebugCalls
  1055.         #define cnv16RGx2to16DPFx2(a)        DebugStr("\pcnv16RGx2to16DPFx2")
  1056.     #else
  1057.         #error "cnv16RGx2to16DPFx2(a) not defined for this case in BltMacros.h";
  1058.     #endif
  1059. #elif dstIs16LE565                    //            r+g1+g2                    g2n+b                            r2+g3+g4                    g4n+b2                                    g2                                    
  1060. #define cnv16RGx2to16DPFx2(a)        a = ((((a)&0x7fe00000)>>15) | (((a)&0x003f0000)>>16) | (((a)&0x00007fe0)<<17) | ((((unsigned long)(a))&0x0000003f)<<16))
  1061. #else
  1062.     #if TempAllowDebugCalls
  1063.         #define cnv16RGx2to16DPFx2(a)        DebugStr("\pcnv16RGx2to16DPFx2")
  1064.     #else
  1065.         #error "cnv16RGx2to16DPFx2(a) not defined for this case in BltMacros.h";
  1066.     #endif
  1067. #endif
  1068.  
  1069. #undef cnv32SPFto32AR
  1070. #if srcIs32ARGB
  1071. #define cnv32SPFto32AR(a)        N2BEndianU32(a)
  1072. #elif srcIs32BGRA
  1073. #define cnv32SPFto32AR(a)        N2LEndianU32(a)
  1074. #elif srcIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  1075. #define cnv32SPFto32AR(a)        from32wxyzto32zwxy(a)
  1076. #elif srcIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  1077. #define cnv32SPFto32AR(a)        from32wxyzto32wzyx(a)
  1078. #elif srcIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  1079. #define cnv32SPFto32AR(a)        from32wxyzto32wzyx(a)
  1080. #elif srcIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  1081. #define cnv32SPFto32AR(a)        from32wxyzto32zwxy(a)
  1082. #else
  1083.     #if TempAllowDebugCalls
  1084.         #define cnv32SPFto32AR(a)        DebugStr("\pcnv32SPFto32AR")
  1085.     #else
  1086.         #error "cnv32SPFto32AR(a) not defined for this case in BltMacros.h";
  1087.     #endif
  1088. #endif
  1089.  
  1090.  
  1091. // converts 24 bit src pixel format to 32 dst pixel format, assumes src and dst will be read and written using Get24 and Set32
  1092. #undef cnv24SPFto32DPF
  1093. #if srcIs24RGB
  1094.     #if dstIs32ARGB
  1095.         #define cnv24SPFto32DPF(a)        B2NEndianU32(a)
  1096.     #elif dstIs32BGRA
  1097.         #define cnv24SPFto32DPF(a)        L2NEndianU32(a)
  1098.     #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  1099.         #define cnv24SPFto32DPF(a)        from32wxyzto32xyzw(a)
  1100.     #elif dstIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  1101.         #define cnv24SPFto32DPF(a)        from32wxyzto32wzyx(a)
  1102.     #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  1103.         #define cnv24SPFto32DPF(a)        from32wxyzto32wzyx(a)
  1104.     #elif dstIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  1105.         #define cnv24SPFto32DPF(a)        from32wxyzto32xyzw(a)
  1106.     #else
  1107.         #if TempAllowDebugCalls
  1108.             #define cnv24SPFto32DPF(a)    DebugStr("\pcnv24SPFto32DPF")
  1109.         #else
  1110.             #error "cnv24SPFto32DPF(a) not defined for this case in BltMacros.h";
  1111.         #endif
  1112.     #endif
  1113. #elif srcIs24BGR
  1114.     #if dstIs32ARGB && TARGET_RT_LITTLE_ENDIAN
  1115.         #define cnv24SPFto32DPF(a)        from32wxyzto32xyzw(a)
  1116.     #elif dstIs32ARGB && !TARGET_RT_LITTLE_ENDIAN
  1117.         #define cnv24SPFto32DPF(a)        from32wxyzto32wzyx(a)
  1118.     #elif dstIs32BGRA && TARGET_RT_LITTLE_ENDIAN
  1119.         #define cnv24SPFto32DPF(a)        from32wxyzto32wzyx(a)        
  1120.     #elif dstIs32BGRA && !TARGET_RT_LITTLE_ENDIAN
  1121.         #define cnv24SPFto32DPF(a)        from32wxyzto32xyzw(a)        
  1122.     #elif dstIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  1123.         #define cnv24SPFto32DPF(a)        from32wxyzto32zyxw(a)
  1124.     #elif dstIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  1125.         #define cnv24SPFto32DPF(a)        
  1126.     #else
  1127.         #if TempAllowDebugCalls
  1128.             #define cnv24SPFto32DPF(a)    DebugStr("\pcnv24SPFto32DPF")
  1129.         #else
  1130.             #error "cnv24SPFto32DPF(a) not defined for this case in BltMacros.h";
  1131.         #endif
  1132.     #endif
  1133. #else
  1134.     #if TempAllowDebugCalls
  1135.         #define cnv24SPFto32DPF(a)    DebugStr("\pcnv24SPFto32DPF")
  1136.     #else
  1137.         #error "cnv24SPFto32DPF(a) not defined for this case in BltMacros.h";
  1138.     #endif
  1139. #endif
  1140.  
  1141.  
  1142. // converts 32 src pixel format to 24 dst pixel format, assumes src and dst will be read and written using Get32 and Set24
  1143. #undef cnv32SPFto24DPF
  1144. #if srcIs32ARGB
  1145.     #if dstIs24RGB && TARGET_RT_LITTLE_ENDIAN
  1146.         #define cnv32SPFto24DPF(a)        SwapU32(a)
  1147.     #elif dstIs24RGB && !TARGET_RT_LITTLE_ENDIAN
  1148.         #define cnv32SPFto24DPF(a)
  1149.     #elif dstIs24BGR
  1150.         #define cnv32SPFto24DPF(a)        from32wxyzto32zwxy(a)
  1151.     #else
  1152.         #if TempAllowDebugCalls
  1153.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1154.         #else
  1155.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1156.         #endif
  1157.     #endif
  1158. #elif srcIs32ARGB && !TARGET_RT_LITTLE_ENDIAN
  1159.     #if dstIs24RGB
  1160.         #define cnv32SPFto24DPF(a)
  1161.     #elif dstIs24BGR
  1162.         #define cnv32SPFto24DPF(a)        from32wxyzto32wzyx(a)
  1163.     #else
  1164.         #if TempAllowDebugCalls
  1165.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1166.         #else
  1167.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1168.         #endif
  1169.     #endif
  1170. #elif srcIs32BGRA  && !TARGET_RT_LITTLE_ENDIAN
  1171.     #if dstIs24RGB 
  1172.         #define cnv32SPFto24DPF(a)        SwapU32(a)
  1173.     #elif dstIs24BGR
  1174.         #define cnv32SPFto24DPF(a)        from32wxyzto32zwxy(a)
  1175.     #else
  1176.         #if TempAllowDebugCalls
  1177.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1178.         #else
  1179.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1180.         #endif
  1181.     #endif
  1182. #elif srcIs32BGRA && TARGET_RT_LITTLE_ENDIAN
  1183.     #if dstIs24RGB
  1184.         #define cnv32SPFto24DPF(a)
  1185.     #elif dstIs24BGR
  1186.         #define cnv32SPFto24DPF(a)        from32wxyzto32wzyx(a)
  1187.     #else
  1188.         #if TempAllowDebugCalls
  1189.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1190.         #else
  1191.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1192.         #endif
  1193.     #endif
  1194. #elif srcIs32ABGR && TARGET_RT_LITTLE_ENDIAN
  1195.     #if dstIs24RGB
  1196.         #define cnv32SPFto24DPF(a)        from32wxyzto32zwxy(a)
  1197.     #elif dstIs24BGR
  1198.         #define cnv32SPFto24DPF(a)        from32wxyzto32zyxw(a)
  1199.     #else
  1200.         #if TempAllowDebugCalls
  1201.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1202.         #else
  1203.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1204.         #endif
  1205.     #endif
  1206. #elif srcIs32ABGR && !TARGET_RT_LITTLE_ENDIAN
  1207.     #if dstIs24RGB
  1208.         #define cnv32SPFto24DPF(a)        from32wxyzto32wzyx(a)
  1209.     #elif dstIs24BGR
  1210.         #define cnv32SPFto24DPF(a)        
  1211.     #else
  1212.         #if TempAllowDebugCalls
  1213.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1214.         #else
  1215.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1216.         #endif
  1217.     #endif
  1218. #elif srcIs32RGBA && !TARGET_RT_LITTLE_ENDIAN
  1219.     #if dstIs24RGB
  1220.         #define cnv32SPFto24DPF(a)        from32wxyzto32zwxy(a)
  1221.     #elif dstIs24BGR
  1222.         #define cnv32SPFto24DPF(a)        from32wxyzto32zyxw(a)
  1223.     #else
  1224.         #if TempAllowDebugCalls
  1225.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1226.         #else
  1227.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1228.         #endif
  1229.     #endif
  1230. #elif srcIs32RGBA && TARGET_RT_LITTLE_ENDIAN
  1231.     #if dstIs24RGB
  1232.         #define cnv32SPFto24DPF(a)        from32wxyzto32wzyx(a)
  1233.     #elif dstIs24BGR
  1234.         #define cnv32SPFto24DPF(a)        
  1235.     #else
  1236.         #if TempAllowDebugCalls
  1237.             #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1238.         #else
  1239.             #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1240.         #endif
  1241.     #endif
  1242. #else
  1243.     #if TempAllowDebugCalls
  1244.         #define cnv32SPFto24DPF(a)    DebugStr("\pcnv32SPFto24DPF")
  1245.     #else
  1246.         #error "cnv32SPFto24DPF(a) not defined for this case in BltMacros.h";
  1247.     #endif
  1248. #endif
  1249.